//
//  CoachTabBarController.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/9/12.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "CoachTabBarController.h"
#import "TeachController.h"
#import "MineController.h"
#import "AppDelegate+UPush.h"

@interface CoachTabBarController ()

@end

static CoachTabBarController *shareTabBar = nil;
@implementation CoachTabBarController

+(CoachTabBarController *)shareLZHTabbarController{
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        shareTabBar = [[CoachTabBarController alloc]init];
    });
    return shareTabBar;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.tabBar setHidden:NO];
    //重置友盟推送别名
    AppDelegate * appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [appDelegate setAliasWithSelectNum:0];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTabBar];
}

#pragma mark ==========设置TabBar==========
- (void)createTabBar{
    //顶端添加分割线
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -0.5, SCREEN_WIDTH, SCALEUNIT)];
    view.backgroundColor = RGBA(210, 210, 210, 1);
    [[UITabBar appearance] insertSubview:view atIndex:0];
    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
    [self.tabBar setBackgroundColor:[UIColor whiteColor]];
    TeachController *teachController = [[TeachController alloc] init];
    [self setTabBarItem:teachController
                  title:@"教学"
                  image:[UIImage imageNamed:@"CoachTabBarTeachImgNormal"]
          selectedImage:[UIImage imageNamed:@"CoachTabBarTeachImgSelect"]];
    UINavigationController *car = [[UINavigationController alloc] initWithRootViewController:teachController];
    
    MineController *mineController = [[MineController alloc] init];
    [self setTabBarItem:mineController
                  title:@"我的"
                  image:[UIImage imageNamed:@"CoachTabBarMineNormal"]
          selectedImage:[UIImage imageNamed:@"CoachTabBarMineSelect"]];
    UINavigationController *mine = [[UINavigationController alloc] initWithRootViewController:mineController];
    self.viewControllers = [NSArray arrayWithObjects:car, mine, nil];
}


- (void)setTabBarItem:(UIViewController *)viewController
                title:(NSString *)title
                image:(UIImage *)image
        selectedImage:(UIImage *)selectedImage
{
    viewController.tabBarItem.title = title;
    if (image) {
        viewController.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    if (selectedImage) {
        viewController.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    
    [viewController.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:149/255.0 green:149/255.0 blue:149/255.0 alpha:1], NSForegroundColorAttributeName,[UIFont systemFontOfSize:LoginFont-4],NSFontAttributeName, nil] forState:UIControlStateNormal];
    [viewController.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:90/255.0f green:204/255.0f blue:255/255.0f alpha:1.0f], NSForegroundColorAttributeName,[UIFont systemFontOfSize:LoginFont-4],NSFontAttributeName, nil] forState:UIControlStateSelected];
    viewController.tabBarItem.titlePositionAdjustment= UIOffsetMake(0, -2);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
